
/*---------------------------------------------------------------------------
新建文件
//////---------设备模型的统一接口-------------

---------------------------------------------------------------------------*/

#include <stdint.h>

//#include "iot_message.pb.h"

#include "dev_air_cond.h"
#include "dev_battery.h"
#include "dev_dc_meter.h"
#include "dev_DIDO.h"
#include "dev_ac_meter.h"
#include "dev_smoke.h"
#include "dev_temper.h"
#include "dev_water.h"
#include "iot_node.h"
#include "dev_lamp.h"             ////路灯节点模型
#include "dev_liquid_level.h"    ////液位传感器模型
#include "dev_generator.h" 

#include "dev_manager.h"
#include "dev_module.h"        ///---------设备模型对外统一接口-------------
#include "iot_node_func.h"
#include "iotv30_config.h"
#include "uart_printf.h"



/**
 * @brief 
 * 
 */
void  dev_module_param_init(void)
{


}



/**
 * @brief 
 * 
 * @param out 
 */
void  dev_module_attr_get( uint16_t sub_uid, void* out)  ////liquid_attr_t
{
 uint8_t   index;
 uint16_t node_type;


     //本方法按类型读取
     if( !iot_find_node_index_with_sub_uid( sub_uid, &index ) )
     {//对应节点不存在
        return ;      
     }

     node_type = iot_get_node_type_with_index( index );  
 
   switch(node_type)
   {
        case IOT_SENSOR_liquid:
        {
           *( (liquid_attr_t*) out) = *liquid_get_obj(index );
        }break;


        case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
        {   
            *( (temp_humi_attr_t*) out) = *temp_humi_get_obj(index );
        }break;

        case IOT_SENSOR_smoke:
        {
            *( (smoke_attr_t*) out) = *smoke_get_obj(index ); 
        }break;

        case IOT_SENSOR_water:
        {
            *( ( dev_water_attr_t*) out) = *dev_water_get_obj(index ); 
        }break;

        case IOT_SENSOR_dido:
        {
            *( (dev_dido_attr_t*) out) = *dev_dido_get_obj(index );
        }break;

        case IOT_SENSOR_ac_meter:
        { 
            *( (ac_meter_attr_t*) out) = *ac_meter_get_obj(index );
        }break;

        case IOT_SENSOR_dc_meter:
        {  
             *( (dc_meter_attr_t*) out) = *dc_meter_get_obj(index );
        }break;

        case IOT_SENSOR_battery:
        {   
            *( (battery_attr_t*) out) = *battery_get_obj(index );
        }break;

        case IOT_SENSOR_air_cond:
        {
             *( (air_cond_attr_t*) out) = *air_cond_get_obj(index );
        }break;

        case IOT_SENSOR_generator:
        {
            *( (generator_attr_t*) out) = *generator_get_obj(index );
        }break;


        default:
        {     
        }break;


    /////路灯电源节点
      //lamp_attr_get( (lamp_attr_t*) out); 

   } ////---switch----------------


}






 uint8_t  dev_module_get_run_data_len( uint16_t node_type )  
 {
 // uint8_t   index;
 // uint16_t node_type;
 
  //    node_type = iot_get_node_type_with_index( index );  
  
    switch(node_type)
    {
         case IOT_SENSOR_liquid:
         {
            return (liquid_index_run_data_end - liquid_index_run_data_begin);
         }break;
 
 
         case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
         {   
            return (temp_humi_index_run_data_end - temp_humi_index_run_data_begin);
         }break;
 
         case IOT_SENSOR_smoke:
         {
             return (smoke_index_run_data_end - smoke_index_run_data_begin);
         }break;
 
         case IOT_SENSOR_water:
         {
             return (dev_water_index_run_data_end - dev_water_index_run_data_begin);  
         }break;
 
         
         case IOT_SENSOR_dido:
         {
              return (dev_dido_index_run_data_end - dev_dido_index_run_data_begin );
          }break;
 
         case IOT_SENSOR_generator: 
         {
              return (generator_index_run_data_end - generator_index_run_data_begin );
          }break;

         case IOT_SENSOR_ac_meter:
         { 
             return (ac_meter_index_run_data_end - ac_meter_index_run_data_begin);
         }break;
 
         case IOT_SENSOR_dc_meter:
         {  
              return (dc_meter_index_run_data_end - dc_meter_index_run_data_begin);
         }break;
 
         case IOT_SENSOR_battery:
         {   
             return (battery_index_run_data_end - battery_index_run_data_begin);  
          }break;
 
         case IOT_SENSOR_air_cond:
         {
              return (air_cond_index_run_data_end - air_cond_index_run_data_begin);
         }break;
 
 
         default:
         {     return 0;
         }break;
 
    } ////---switch----------------
 

 }
 
 


 uint8_t  dev_module_get_config_data_len( uint16_t node_type )  
 {
  
    switch(node_type)
    {
         case IOT_SENSOR_liquid:
         {
            return (liquid_index_factory_info_begin - liquid_index_config_data_begin);
         }break;
 
 
         case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
         {   
            return (temp_humi_index_factory_info_begin - temp_humi_index_config_data_begin);
         }break;
 
         case IOT_SENSOR_smoke:
         {
             return (smoke_index_factory_info_begin - smoke_index_config_data_begin);
         }break;
 
         case IOT_SENSOR_water:
         {
             return (dev_water_index_factory_info_begin - dev_water_index_config_data_begin);  
         }break;
 
         
         case IOT_SENSOR_dido:
         {
              return (dev_dido_index_factory_info_begin - dev_dido_index_config_data_begin);
          }break;
 
         case IOT_SENSOR_generator: 
         {
              return (generator_index_factory_info_begin - generator_index_config_data_begin);
          }break;
 


         case IOT_SENSOR_ac_meter:
         { 
             return (ac_meter_index_factory_info_begin - ac_meter_index_config_data_begin);
         }break;
 
         case IOT_SENSOR_dc_meter:
         {  
              return (dc_meter_index_factory_info_begin - dc_meter_index_config_data_begin);
         }break;
 
         case IOT_SENSOR_battery:
         {   
             return (battery_index_factory_info_begin - battery_index_config_data_begin);  
          }break;
 
         case IOT_SENSOR_air_cond:
         {
              return (air_cond_index_factory_info_begin - air_cond_index_config_data_begin);
         }break;
 
 
         default:
         {     return 0;
         }break;
 
    } ////---switch----------------
 

 }
 
 




 uint16_t*  dev_module_get_config_table( uint16_t node_type )  
 {
  
    switch(node_type)
    {
         case IOT_SENSOR_liquid:
         {
            return ( uint16_t*) &liquid_iot_id_table[liquid_index_config_data_begin];
         }break;
 
 
         case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
         {   
            return  ( uint16_t*)&temp_humi_iot_id_table[temp_humi_index_config_data_begin];
         }break;
 
         case IOT_SENSOR_smoke:
         {
             return ( uint16_t*)&smoke_iot_id_table[smoke_index_config_data_begin]; 
         }break;
 
         case IOT_SENSOR_water:
         {
             return ( uint16_t*)&dev_water_iot_id_table[dev_water_index_config_data_begin]; 
         }break;
 
         
         case IOT_SENSOR_dido:
         {
              return ( uint16_t*)&dev_dido_iot_id_table[dev_dido_index_config_data_begin];
          }break;
 

         case IOT_SENSOR_generator: 
         {
              return ( uint16_t*)&generator_iot_id_table[generator_index_config_data_begin];
          }break;
 


         case IOT_SENSOR_ac_meter:
         { 
             return ( uint16_t*)&ac_meter_iot_id_table[ac_meter_index_config_data_begin];
         }break;
 
         case IOT_SENSOR_dc_meter:
         {  
              return ( uint16_t*)&dc_meter_iot_id_table[dc_meter_index_config_data_begin]; 
         }break;
 
         case IOT_SENSOR_battery:
         {   
             return ( uint16_t*)&battery_iot_id_table[battery_index_config_data_begin]; 
          }break;
 
         case IOT_SENSOR_air_cond:
         {
              return ( uint16_t*)&air_cond_iot_id_table[air_cond_index_config_data_begin]; 
         }break;
 
 
         default:
         {     return 0;
         }break;
 
    } ////---switch----------------
 

 }
 





/**
 * @brief  //按类型读取  
 * 
 * @param attr_id 
 * @param attr_out 
 * @return attr_cnt
 */

 /*-------------------------------------------------
int16_t  dev_module_read_attr( uint16_t sub_uid,dev_read_type_e read_type, void* attr_out) 
{
 uint8_t  index =0;   
 uint16_t cnt = 0;
 uint16_t node_type;
 IotModel*  pattr = (IotModel*)attr_out;

// typedef enum{
//     dev_read_point = 0,     //0：读取指定测量点
//     dev_read_run_data ,     // 1：读取设备运行参数
//     dev_read_config_data,   // 2：读取设备配置参数
//     dev_read_factory_info,  // 3：读取设备出厂信息
// } dev_read_type_e;


     if( dev_read_point == read_type) //0：读取指定测量点
     {//读取指定测量点---则返回
        return 0;
     }

     //本方法按类型读取
     if( !iot_find_node_index_with_sub_uid( sub_uid, &index ) )
     {//对应节点不存在
     
        return 0;      
     }

     node_type = iot_get_node_type_with_index( index );  
 
    // if( false == devm_get_node_type( sub_uid, &node_type ) )  
    // {
    //     return 0;
    // }

......
}

------------------------------------------------*/


/**
 * @brief  //按类型读取  
 * 
 * @param attr_id 
 * @param attr_out 
 * @return attr_cnt
 */

uint16_t  dev_module_read_attr( uint16_t index,dev_read_type_e read_type,void* attr_out ) 
{
uint16_t node_type;
 uint16_t attr_idx,cnt;
 IotModel*  pattr = (IotModel*)attr_out;

// typedef enum{
//     dev_read_point = 0,     //0：读取指定测量点
//     dev_read_run_data ,     // 1：读取设备运行参数
//     dev_read_config_data,   // 2：读取设备配置参数
//     dev_read_factory_info,  // 3：读取设备出厂信息
// } dev_read_type_e;

     LOG_NAME();

     if( dev_read_point == read_type) //0：读取指定测量点
     {//读取指定测量点---则返回
        return 0;
     }


     node_type = iot_get_node_type_with_index( index );  
 
    // if( false == devm_get_node_type( sub_uid, &node_type ) )  
    // {
    //     return 0;
    // }


   cnt = 0;
   switch (node_type)
   {
        case  IOT_SENSOR_liquid :  
        {///液位传感器节点------

            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =liquid_index_run_data_begin ; attr_idx < liquid_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    liquid_get_attr(index,liquid_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =liquid_index_config_data_begin ; attr_idx < liquid_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    liquid_get_attr(index,liquid_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =liquid_index_factory_info_begin ; attr_idx < liquid_index_end; attr_idx++)
                { // 设备运行参数
                    liquid_get_attr(index,liquid_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }
        }  break;
 

// 0x0520	烟雾报警信息	RO	
// 0x0602	设备通道编号	R/W	
// 0x0620	烟雾报警使能	R/W
// 0x0621	报警延时时间	R/W

        case  IOT_SENSOR_smoke :  
        {//

            // if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            // {//运行参数

            //     smoke_get_attr(index,0x0520, &pattr[0]); //// 0x0520	烟雾报警信息	RO	
            //     cnt = 1;
            // }

            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =smoke_index_run_data_begin ; attr_idx < smoke_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    smoke_get_attr(index,smoke_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =smoke_index_config_data_begin ; attr_idx < smoke_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    smoke_get_attr(index,smoke_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =smoke_index_factory_info_begin ; attr_idx < smoke_index_end; attr_idx++)
                { // 设备运行参数
                    smoke_get_attr(index,smoke_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;
 

// 0x0510	温湿度报警信息	RO	是	运行参数
// 0x0511	湿度	RO	否	运行参数				
// 0x0502	温度	RO	否	运行参数
						
// 0x0602	设备通道编号	R/W	否	配置参数
				
// 0x0606	温度过低阈值	R/W	否	配置参数
// 0x0607	温度过高阈值	R/W	否	配置参数
				
// 0x0610	温湿度报警使能	R/W	否	配置参数
// 0x0611	湿度过低阈值	R/W	否	配置参数
// 0x0612	湿度过高阈值	R/W	否	配置参数
// 0x0613	温度变化监测周期	R/W	否	配置参数
// 0x0614	温度变化异常值	R/W	否	配置参数
// 0x0615	湿度变化监测周期	R/W	否	配置参数
// 0x0616	湿度变化异常值	R/W	否	配置参数


        case  IOT_SENSOR_temper_humidity :  
        {//

            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =temp_humi_index_run_data_begin ; attr_idx < temp_humi_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    temp_humi_get_attr(index,temp_humi_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =temp_humi_index_config_data_begin ; attr_idx < temp_humi_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    temp_humi_get_attr(index,temp_humi_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =temp_humi_index_factory_info_begin ; attr_idx < temp_humi_index_end; attr_idx++)
                { // 设备运行参数
                    temp_humi_get_attr(index,temp_humi_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;


       case  IOT_SENSOR_water :  
        {//
            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =dev_water_index_run_data_begin ; attr_idx < dev_water_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    dev_water_get_attr(index,dev_water_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =dev_water_index_config_data_begin ; attr_idx < dev_water_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    dev_water_get_attr(index,dev_water_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =dev_water_index_factory_info_begin ; attr_idx < dev_water_index_end; attr_idx++)
                { // 设备运行参数
                    dev_water_get_attr(index,dev_water_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;


       case IOT_SENSOR_dido   :   //door 门禁传感器 :  
        {//

            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =dev_dido_index_run_data_begin ; attr_idx < dev_dido_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    dev_dido_get_attr(index,dev_dido_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =dev_dido_index_config_data_begin ; attr_idx < dev_dido_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    dev_dido_get_attr(index,dev_dido_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =dev_dido_index_factory_info_begin ; attr_idx < dev_dido_index_end; attr_idx++)
                { // 设备运行参数
                    dev_dido_get_attr(index,dev_dido_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;



       case IOT_SENSOR_generator :   // oil engine 
        {//

            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =generator_index_run_data_begin ; attr_idx < generator_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    generator_get_attr(index,generator_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =generator_index_config_data_begin ; attr_idx < generator_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    generator_get_attr(index,generator_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =generator_index_factory_info_begin ; attr_idx < generator_index_end; attr_idx++)
                { // 设备运行参数
                    generator_get_attr(index,generator_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;





       case  IOT_SENSOR_ac_meter : 
        {//
            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =ac_meter_index_run_data_begin ; attr_idx < ac_meter_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    ac_meter_get_attr(index,ac_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =ac_meter_index_config_data_begin ; attr_idx < ac_meter_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    ac_meter_get_attr(index,ac_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =ac_meter_index_factory_info_begin ; attr_idx < ac_meter_index_end; attr_idx++)
                { // 设备运行参数
                    ac_meter_get_attr(index,ac_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;



       case  IOT_SENSOR_dc_meter : 
        {//
            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =dc_meter_index_run_data_begin ; attr_idx < dc_meter_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    dc_meter_get_attr(index,dc_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =dc_meter_index_config_data_begin ; attr_idx < dc_meter_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    dc_meter_get_attr(index,dc_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =dc_meter_index_factory_info_begin ; attr_idx < dc_meter_index_end; attr_idx++)
                { // 设备运行参数
                    dc_meter_get_attr(index,dc_meter_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;


       case  IOT_SENSOR_battery : 
        {//
            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =battery_index_run_data_begin ; attr_idx < battery_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    battery_get_attr(index,battery_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =battery_index_config_data_begin ; attr_idx < battery_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    battery_get_attr(index,battery_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =battery_index_factory_info_begin ; attr_idx < battery_index_end; attr_idx++)
                { // 设备运行参数
                    battery_get_attr(index,battery_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;



       case  IOT_SENSOR_air_cond : 
        {//
            if(dev_read_run_data == read_type )  //  1：读取设备运行参数
            {//运行参数
               
            ////每次不应该超过 8个，防止数据溢出
                for( attr_idx =air_cond_index_run_data_begin ; attr_idx < air_cond_index_run_data_end; attr_idx++)
                { // 设备运行参数
                    air_cond_get_attr(index,air_cond_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
            {//配置参数

                for( attr_idx =air_cond_index_config_data_begin ; attr_idx < air_cond_index_factory_info_begin; attr_idx++)
                { // 设备运行参数
                    air_cond_get_attr(index,air_cond_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
            {//产品信息

                for( attr_idx =air_cond_index_factory_info_begin ; attr_idx < air_cond_index_end; attr_idx++)
                { // 设备运行参数
                    air_cond_get_attr(index,air_cond_get_iot_id(attr_idx), &pattr[cnt++]); 
                }

            }else{
                    ////????其它
                cnt = 0;
            }

        }  break;




/*------------------------------------------------------------------------------------
        case  IOT_SENSOR_liquid :  
        {////////路灯电源节点-------?????

                if(dev_read_run_data == read_type )  //  1：读取设备运行参数
                {//运行参数
                    lamp_get_attr(0x0001, &pattr[0]); 
                    lamp_get_attr(0x0021, &pattr[1]);
.....
                }else if(dev_read_config_data == read_type ) // 2：读取设备配置参数
                {//配置参数

                    for(cnt=0;cnt<7;cnt++)
                    {
                        lamp_get_attr(0x0481+cnt, &pattr[cnt]);
                    }

                }else if(dev_read_factory_info == read_type )  // 3：读取设备出厂信息
                {//产品信息

                    for(cnt=0;cnt<4;cnt++)
                    {
                        lamp_get_attr(0x0800+cnt, &pattr[cnt]);
                    }

                }else{
                    ////????其它
                    cnt = 0;
                }

        }  break;
----------------------------------------------------------------------------------*/

      default:
      {
        cnt = 0;
      } break;

   }


return  cnt;

}




/**
 * @brief ////读取指定测量点
 * @param sub_uid 
 * @param attr_id 
 * @param attr_out 
 */
//void  dev_module_get_attr( uint16_t sub_uid,uint16_t attr_id, void* attr_out)   //IotModel
void  dev_module_get_attr( uint16_t index,uint16_t attr_id, void* attr_out)   //IotModel
{
 uint16_t node_type;

  node_type = iot_get_node_type_with_index( index );  

   switch ( node_type) 
   {
        case IOT_SENSOR_liquid:
        {
           liquid_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;
 
    // IOT_SENSOR_temper_humidity = 0xD000,//temperature and humidity 
        case IOT_SENSOR_temper_humidity:
        {
           temp_humi_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;
 
        case IOT_SENSOR_smoke:
        {
           smoke_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;

         case IOT_SENSOR_water:
        {
           dev_water_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;


         case IOT_SENSOR_dido:     //door 门禁传感器
        {
           dev_dido_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;
 

         case IOT_SENSOR_ac_meter:
        {
           ac_meter_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;
 
         case IOT_SENSOR_dc_meter:
        {
           dc_meter_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_battery:
        {
           battery_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_air_cond:  
        {
           air_cond_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_generator:   // oil engine 
        {
           generator_get_attr(index, attr_id,(IotModel*) attr_out);
        }break;


       /////路灯电源节点
       //  lamp_get_attr(attr_id,(IotModel*) attr_out);
        default :
        {        
        }break;
   
   } ///----- switch ( node_type)-----------


}



/**
 * @brief ////读取指定测量点
 * @param node_index 
 * @param attr_id 
 * @param attr_out 
 */
void  dev_module_get_attr_with_node_index( uint8_t node_index,uint16_t attr_id, void* attr_out) 
{
 uint16_t node_type;

  node_type = iot_get_node_type_with_index( node_index );  

   switch(node_type)
   {
        case IOT_SENSOR_liquid:
        {
            liquid_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;


        case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
        {
            temp_humi_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_smoke:
        {
            smoke_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_water:
        {
            dev_water_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_dido:
        {
            dev_dido_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_ac_meter:
        {
            ac_meter_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_dc_meter:
        {
            dc_meter_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_battery:
        {
            battery_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_air_cond:
        {
            air_cond_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_generator:
        {
            generator_get_attr(node_index, attr_id,(IotModel*) attr_out);
        }break;


        default:
        {     
        }break;


    /////路灯电源节点
       //  lamp_get_attr(attr_id,(IotModel*) attr_out);

   } ////---switch----------------


}



/**
 * @brief ////读取指定测量点
 * @param node_index
 * @param attr_index 
 * @param attr_out 
 */
void  dev_module_get_attr_with_node_attr_index( uint8_t node_index,uint16_t attr_index, void* attr_out) 
{
 uint16_t node_type;

    node_type = iot_get_node_type_with_index( node_index );  

   switch(node_type)
   {
        case IOT_SENSOR_liquid:
        {
            liquid_get_attr(node_index, liquid_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;


        case IOT_SENSOR_temper_humidity:  //// 0xD000,//temperature and humidity 
        {
            temp_humi_get_attr(node_index, temp_humi_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_smoke:
        {
            smoke_get_attr(node_index, smoke_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_water:
        {
            dev_water_get_attr(node_index, dev_water_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_dido:
        {
            dev_dido_get_attr(node_index, dev_dido_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_ac_meter:
        {
            ac_meter_get_attr(node_index, ac_meter_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_dc_meter:
        {
            dc_meter_get_attr(node_index, dc_meter_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_battery:
        {
            battery_get_attr(node_index, battery_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_air_cond:
        {
            air_cond_get_attr(node_index, air_cond_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;

        case IOT_SENSOR_generator:
        {
            generator_get_attr(node_index, generator_get_iot_id(attr_index),(IotModel*) attr_out);
        }break;


        default:
        {     
        }break;


    /////路灯电源节点
    // attr_id = liquid_get_iot_id( attr_index );   ////?????
    //   attr_id =  0x0001;///????此处还需要优化
    //  lamp_get_attr(0x0001,(IotModel*) attr_out);

   } ////---switch----------------


}



/**
 * @brief ////读取运行时数据
 * @param node_index
 * @param attr_out 
 * @return 返回iot_id 属性的个数 
 */
uint16_t  dev_module_get_attr_run_data( uint8_t node_index, void* attr_out) 
{
 uint8_t  attr_idx,count;   
 uint16_t node_type;
 uint16_t attr_id;

 //SubIotData* psub_iot_data = (SubIotData*)attr_out;

 IotModel* p_data = (IotModel*)attr_out;

    count = 0;

    node_type = iot_get_node_type_with_index( node_index );  

   switch(node_type)
   {
      case IOT_SENSOR_liquid:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =liquid_index_run_data_begin ; attr_idx < liquid_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = liquid_get_iot_id( attr_idx );
                // liquid_get_attr(node_index, attr_id, p_data+count );
                liquid_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;


      case IOT_SENSOR_temper_humidity:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =temp_humi_index_run_data_begin ; attr_idx < temp_humi_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = temp_humi_get_iot_id( attr_idx );
                temp_humi_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;


      case IOT_SENSOR_smoke:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =smoke_index_run_data_begin ; attr_idx < smoke_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = smoke_get_iot_id( attr_idx );
                smoke_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;


      case IOT_SENSOR_water:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =dev_water_index_run_data_begin ; attr_idx < dev_water_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = dev_water_get_iot_id( attr_idx );
                dev_water_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;



      case IOT_SENSOR_battery:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =battery_index_run_data_begin ; attr_idx < battery_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = battery_get_iot_id( attr_idx );
                battery_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;

      case IOT_SENSOR_dido:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =dev_dido_index_run_data_begin ; attr_idx < dev_dido_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = dev_dido_get_iot_id( attr_idx );
                dev_dido_get_attr(node_index, attr_id, &p_data[count] );
                //logout("report dido run data attr_idx=%d\n",attr_idx);
            }

      }break;


      case IOT_SENSOR_air_cond:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx = air_cond_index_run_data_begin ; attr_idx < air_cond_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                air_cond_get_attr(node_index, air_cond_get_iot_id(attr_idx ), &p_data[count] );
            }

      }break;

      case IOT_SENSOR_generator: //与门禁模块一样共用 dido 模块
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =generator_index_run_data_begin ; attr_idx < generator_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = generator_get_iot_id( attr_idx );
                generator_get_attr(node_index, attr_id, &p_data[count] );
            }

      }break;



      case IOT_SENSOR_ac_meter:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =ac_meter_index_run_data_begin ; attr_idx < ac_meter_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = ac_meter_get_iot_id( attr_idx );
                ac_meter_get_attr(node_index, attr_id, &p_data[count] );
               // logout("report ac_meter run data attr_idx=%d\n",attr_idx);
            }

      }break;

      case IOT_SENSOR_dc_meter:
      {
            ////每次不应该超过 8个，防止数据溢出
            for( attr_idx =dc_meter_index_run_data_begin ; attr_idx < dc_meter_index_run_data_end; attr_idx++, count++)
            { // 设备运行参数
                attr_id = dc_meter_get_iot_id( attr_idx );
                dc_meter_get_attr(node_index, attr_id, &p_data[count] );
                //logout("report dc_meter  run data attr_idx=%d\n",attr_idx);
            }

      }break;


        /////路灯电源节点
#if 0

        // attr_id = liquid_get_iot_id( attr_index );   ////?????
          attr_id =  0x0001;///????此处还需要优化
         lamp_get_attr(attr_id,(IotModel*) attr_out);
#endif

      default :
      {

      }break;

   }

  return count;  ////每次不应该超过 8个，防止数据溢出

}





/**
 * @brief 
 * 
 * @param attr_in 
 * @return uint8_t 
 */
uint8_t  dev_module_set_attr(uint16_t sub_uid,void* attr_in)   //IotModel
{
 uint8_t  index;
 uint16_t node_type;

     //本方法按类型读取--
     if( !iot_find_node_index_with_sub_uid( sub_uid, &index ) )
     {//对应节点不存在
        return 0;      
     }

   node_type = iot_get_node_type_with_index( index ); 

   switch(node_type)
   {
        case IOT_SENSOR_liquid:
        {
           liquid_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_temper_humidity:
        {
            temp_humi_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_smoke:
        {
            smoke_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_water:
        {
            dev_water_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_dido:
        {
            dev_dido_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_ac_meter:
        {
            ac_meter_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_dc_meter:
        {
            dc_meter_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_battery:
        {
            battery_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_air_cond:
        {
            air_cond_set_attr(index, (IotModel*) attr_in);
        }break;

        case IOT_SENSOR_generator:
        {
            generator_set_attr(index, (IotModel*) attr_in);
        }break;


        default:
        {     
        }break;


    /////路灯电源节点
    ////lamp_set_attr( (IotModel*) attr_in);

   } ////---switch----------------


  return 1;

}




/**
 * @brief 
 * 
 * @param attr_in 
 * @return uint8_t 
 */
 uint8_t  dev_module_set_attr_with_index(uint8_t index,void* attr_in)   //IotModel
 {

  uint16_t node_type;
 
    node_type = iot_get_node_type_with_index( index ); 
 
    switch(node_type)
    {
         case IOT_SENSOR_liquid:
         {
            liquid_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_temper_humidity:
         {
             temp_humi_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_smoke:
         {
             smoke_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_water:
         {
             dev_water_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_dido:
         {
             dev_dido_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_ac_meter:
         {
             ac_meter_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_dc_meter:
         {
             dc_meter_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_battery:
         {
             battery_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_air_cond:
         {
             air_cond_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_generator:
         {
             generator_set_attr(index, (IotModel*) attr_in);
         }break;
 
 
         default:
         {     
         }break;
 
 
     /////路灯电源节点
     ////lamp_set_attr( (IotModel*) attr_in);
 
    } ////---switch----------------
 
 
   return 1;
 
 }







 uint8_t  dev_module_add_obj(uint8_t idx,uint8_t channel,uint16_t sub_mac,uint16_t node_type)  
 {

 // uint16_t node_type;
 //   node_type = iot_get_node_type_with_index( index ); 
 
    switch(node_type)
    {
         case IOT_SENSOR_liquid:
         {
            logout("add node obj idx=%d\n",idx);
            liquid_add_obj( idx,channel,sub_mac&0x0FF );
         }break;
 
         case IOT_SENSOR_temper_humidity:
         {
            logout("add node obj idx=%d\n",idx);
            temp_humi_add_obj( idx,channel,sub_mac&0x0FF );
            //temp_humi_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_smoke:
         {
            logout("add node obj idx=%d\n",idx);
            smoke_add_obj( idx,channel,sub_mac&0x0FF );
            //smoke_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_water:
         {
            logout("add node obj idx=%d\n",idx);
            dev_water_add_obj( idx,channel,sub_mac&0x0FF );
            //dev_water_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_dido:
         {
            logout("add node obj idx=%d\n",idx);
            dev_dido_add_obj( idx,channel,sub_mac&0x0FF );
            //dev_dido_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_ac_meter:
         {
            logout("add node obj idx=%d\n",idx);
            ac_meter_add_obj( idx,channel,sub_mac&0x0FF );
            //ac_meter_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_dc_meter:
         {
            logout("add node obj idx=%d\n",idx);
            dc_meter_add_obj( idx,channel,sub_mac&0x0FF );
            //dc_meter_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_battery:
         {
            logout("add node obj idx=%d\n",idx);
            battery_add_obj( idx,channel,sub_mac&0x0FF );
            //battery_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_air_cond:
         {
            logout("add node obj idx=%d\n",idx);
            air_cond_add_obj( idx,channel,sub_mac&0x0FF );
            //air_cond_set_attr(index, (IotModel*) attr_in);
         }break;
 
         case IOT_SENSOR_generator:
         {
            logout("add node obj idx=%d\n",idx);
            generator_add_obj( idx,channel,sub_mac&0x0FF );
            //generator_set_attr(index, (IotModel*) attr_in);
         }break;
 
 
         default:
         {     
         }break;
 
 
     /////路灯电源节点
     ////lamp_set_attr( (IotModel*) attr_in);
 
    } ////---switch----------------
 
 
   return 1;
 
 }






// 上行命令 65H(7.3.3.1 读取子设备属性) 读取类型(read_type) 取值为0(读取指定测量点)时 的缓存数据

static iot_id_value_st  pb_65H_read_type_0_iot_id_buf[pb_65H_read_type_0_iot_id_MAX];



/**
 * @brief // 上行命令 65H(7.3.3.1 读取子设备属性) 读取类型(read_type) 取值为0(读取指定测量点)时 缓存数据的接口函数
 * @param index 
 * @param iot_id 
 * @param value 
 */
void  dev_module_65H_read_type_0_set( uint16_t index,uint32_t iot_id, int64_t value)   
{

    if(index>=pb_65H_read_type_0_iot_id_MAX)
    {
        logout("type_0_iot_id_buf[%d] array outofrange\n",index);
        return;
    }
    pb_65H_read_type_0_iot_id_buf[index].iot_id = iot_id ;
    pb_65H_read_type_0_iot_id_buf[index].value  = value ;
   
}



void  dev_module_65H_read_type_0_get( uint16_t index,uint16_t attr_id, void* attr_out )  
{
    IotModel*  pattr_out = (IotModel*) attr_out ;

    //assert()
    if(index>=pb_65H_read_type_0_iot_id_MAX)
    {
        logout("type_0_iot_id_buf[%d] array outofrange\n",index);        
        return;
    }

    pattr_out->iot_id = pb_65H_read_type_0_iot_id_buf[index].iot_id;
    pattr_out->value  = pb_65H_read_type_0_iot_id_buf[index].value;
}









